<template>
  <div class="data_list">
    <!-- 按钮 -->
    <div class="btns">
      <el-form :inline="true" size="small">
        <el-form-item>
          <el-button @click="toAdd" size="small" type="primary">上报</el-button>
        </el-form-item>
        <el-form-item>
          <el-input v-model="param.province" size="small" placeholder="请输入省份名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="loadEpidemicData">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 列表 -->
    <el-table :data="epidemics.list" size="small">
      <el-table-column label="序号" type="index" :index="1"></el-table-column>
      <el-table-column label="国" prop="country" width="120"></el-table-column>
      <el-table-column label="省" prop="province" width="100"></el-table-column>
      <el-table-column label="市" prop="city" width="100"></el-table-column>
      <el-table-column label="区" prop="area"></el-table-column>
      <el-table-column label="新增确诊" prop="confirmed" align="center" width="80"></el-table-column>
      <el-table-column label="新增疑似" align="center" width="80">
        <template v-slot:default="scope">
          <el-tag type="warning" size="mini">{{scope.row.suspected}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="新增死亡" align="center" width="80">
        <template v-slot:default="scope">
          <el-tag type="info" size="mini">{{scope.row.dead}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="新增治愈" align="center" width="80">
        <template v-slot:default="scope">
          <el-tag type="success" size="mini">{{scope.row.cure}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="新增重症" align="center" width="80">
        <template v-slot:default="scope">
          <el-tag type="danger" size="mini">{{scope.row.severe}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="境外输入" prop="outside" align="center" width="80"></el-table-column>
      <el-table-column label="上报时间" align="center" width="150">
        <template v-slot:default="scope">{{scope.row.inputTime | fmtDate}}</template>
      </el-table-column>
    </el-table>
    <!-- 列表 -->
    <!-- 分页 -->
    <center>
      <el-pagination
        v-if="epidemics.total > param.pageSize"
        layout="prev, pager, next"
        @current-change="currentChangeHandler"
        :current-page="param.page"
        :page-size="param.pageSize"
        :total="epidemics.total"
      ></el-pagination>
    </center>

    <!-- /分页 -->
  </div>
</template>

<script>
import { get } from "@/utils/request";

export default {
  data() {
    return {
      param: {
        page: 1,
        pageSize: 10,
      },
      epidemics: {},
    };
  },
  created() {
    this.loadEpidemicData();
  },
  methods: {
    //加载所有疫情数据
    loadEpidemicData() {
      let url = "/epidemic/pageQuery";
      get(url, this.param).then((response) => {
        this.epidemics = response.data;
      });
    },
    // 跳转去上报
    toAdd() {
      this.$router.push({
        path: "/data/input",
      });
    },
    //实现分页
    currentChangeHandler(page) {
      this.param.page = page;
      this.loadEpidemicData();
    },
  },
};
</script>